#!/usr/local/bin/node
var id = process.argv[2];

var randomcosa1=Math.random();
var randomcosa2=Math.random();

var db = require('nano')('http://localhost:5984/').use("prueba");
db.get( id, null, do_stuff );

// -------------------------------------------------------------------------------
function do_stuff(error,data) {
    console.log(data);
    data.cosa1=randomcosa1;
    data.cosa2=randomcosa2;
    var result = 0;
    for (var i in data.vector) {
        result += data.vector[i];
    }
    data.result = result;
    console.log( 'Resultado ' + result );
    db.insert( data, id, 
               function(error,resp) {
                   console.log( resp );
               } );
}
